<!DOCTYPE HTML>
<html>

<head>
    <title>proton.js-render-domrender</title>
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta charset="utf-8">
    <style type="text/css">
        body {
            background-color: #333333;
            margin: 0px;
            overflow: hidden;
        }
        
        #container {
            width: 1003px;
            height: 610px;
            margin-top: 50px;
            margin-left: -501px;
            left: 50%;
            position: absolute;
            overflow: hidden;
        }

        .radial {
            background: -webkit-radial-gradient(#147AFF, #000);
            background: -o-radial-gradient(#147AFF, #000);
            background: -moz-radial-gradient(#147AFF, #000);
            background: radial-gradient(#147AFF, #000);
            box-shadow: 0 0 10px #000;
        }
    </style>
</head>

<body>
    <div id="container" class="radial">
        <canvas id="testCanvas"></canvas>
    </div>
    <script src="../../lib/requestAnimationFrame.min.js"></script>
    <script src="../../lib/stats.min.js"></script>
    <script src="//localhost:3001/build/proton.js"></script>
    <script>
        var gl;
        var proton;
        var renderer;
        var stats;

        Main();

        function Main() {
            canvas = document.getElementById("testCanvas");
            canvas.width = 1003;
            canvas.height = 610;
            gl = canvas.getContext('experimental-webgl');
            addStats();

            createProton();
            tick();
        }

        function addStats() {
            stats = new Stats();
            stats.setMode(2);
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.left = '0px';
            stats.domElement.style.top = '0px';
            document.getElementById('container').appendChild(stats.domElement);
        }

        function createProton() {
            proton = new Proton;
            createImageEmitter();
            createColorEmitter();
            
            renderer = new Proton.WebGLRenderer(canvas);
            proton.addRenderer(renderer);
        }

        function createImageEmitter() {
            var emitter = new Proton.Emitter();
            emitter.rate = new Proton.Rate(new Proton.Span(32, 37), new Proton.Span(.2, .5));
            
            emitter.addInitialize(new Proton.Mass(1));
            emitter.addInitialize(new Proton.Life(1, 5));
            emitter.addInitialize(new Proton.Body(['image/fox.png', 'image/safari.png', 'image/chrome.png'], 100, 100));
            emitter.addInitialize(new Proton.Radius(40));
            emitter.addInitialize(new Proton.V(new Proton.Span(4, 8), new Proton.Span(0, 40, true), 'polar'));
            
            emitter.addBehaviour(new Proton.Alpha(1, 0));
            emitter.addBehaviour(new Proton.Scale(.7, 0));
            emitter.addBehaviour(new Proton.Gravity(5.5));
            emitter.addBehaviour(new Proton.Color('random'));
            emitter.addBehaviour(new Proton.Rotate(new Proton.Span(0, 360), new Proton.Span(-15, 15), 'add'));
            emitter.addBehaviour(new Proton.CrossZone(new Proton.RectZone(0, 0, 1003, 610), 'dead'));
            
            emitter.p.x = 1003 / 2;
            emitter.p.y = 610 / 2;
            emitter.emit();
            proton.addEmitter(emitter);
        }

        function createColorEmitter() {
            var emitter = new Proton.Emitter();
            emitter.rate = new Proton.Rate(new Proton.Span(16, 19), new Proton.Span(.1, .2));
            
            emitter.addInitialize(new Proton.Mass(1));
            emitter.addInitialize(new Proton.Radius(1, 20));
            emitter.addInitialize(new Proton.Life(1, 2));
            emitter.addInitialize(new Proton.V(new Proton.Span(1, 4), new Proton.Span(0, 360), 'polar'));
            
            emitter.addBehaviour(new Proton.Alpha(1, 0));
            emitter.addBehaviour(new Proton.Scale(1, 0));
            emitter.addBehaviour(new Proton.Color('random'));
            emitter.addBehaviour(new Proton.CrossZone(new Proton.CircleZone(1003 / 2, 610 / 2, 250), 'dead'));
            emitter.p.x = 1003 / 2;
            emitter.p.y = 610 / 2;
            
            emitter.emit();
            proton.addEmitter(emitter);
        }

        function tick() {
            requestAnimationFrame(tick);

            stats.begin();
            proton.update();
            stats.end();
        }
    </script>
</body>

</html>